package server.utils;

import java.util.ArrayList;

import server.Server;
/**
 * 
 * @author SIIM
 *
 */
public class Configurations {

	private boolean console;
	private int minPlayers;
	private String serverName;
	private int maxPlayers;
	private int initialMoney;
	private int maxPlayerHand;
	private int firstCardsTable;
	private int cardsDealedRound;
	private int roundLimit;
	private int port;
	private String serverAddr;
	/**
	 * Server configurations(appearance order like in file):
	 * #boolean{console} - {true, flase} //server log writing options. 
	 * 							//True - writes to logfile and console. 
	 * 							//False - logfile only.
	 * #int{minPlayers} //nr of min players to start a game
	 * #String{serverName} //server name
	 * #int{MaxPlayers} //nr of max players in game
	 * #int{initialMoney} //player's initial money
	 * #int{maxPlayerHand} //player's max handsize
	 * #int{firstCardsTable} //nr of cards to put on table at first
	 * #int{cardsDealedRound} //nr of cards dealed during rounds
	 * #int{roundLimit} //nr of rounds
	 * #int{port} //server port's nr
	 * #String{serverAddr} //address to server
	 * @param confs Configurations from arralyList
	 * @throws Exception Parsing error.
	 */
	public Configurations(ArrayList<String> confs) throws Exception {
		try {
			this.console = Boolean.parseBoolean(confs.get(0));
			this.minPlayers = Integer.parseInt(confs.get(1));
			this.serverName = confs.get(2);
			this.maxPlayers = Integer.parseInt(confs.get(3));
			this.initialMoney = Integer.parseInt(confs.get(4));
			this.maxPlayerHand = Integer.parseInt(confs.get(5));
			this.firstCardsTable = Integer.parseInt(confs.get(6));
			this.cardsDealedRound = Integer.parseInt(confs.get(7));
			this.roundLimit = Integer.parseInt(confs.get(8));
			this.port = Integer.parseInt(confs.get(9));
			this.serverAddr = confs.get(10);
			String add = "\n\t\t\t";
			String conf = "Server conf:";
			conf += add + "[Writing to console: " + console + "]";
			conf += add + "[Min players: " + minPlayers + "]";
			conf += add + "[Max players: " + maxPlayers + "]";
			conf += add + "[Player's max handsize: " + maxPlayerHand + "]";
			conf += add + "[Player's initial money: " + initialMoney + "]";
			conf += add + "[Cards dealed to table @ first round: " + firstCardsTable + "]";
			conf += add + "[Cards dealed to table during round: " + cardsDealedRound + "]";
			conf += add + "[Nr of rounds: " + roundLimit + "]";
			conf += add + "[Server's name: " + serverName + "]";
			conf += add + "[Server's port: " + port + "]";
			conf += add + "[Server's address: " + serverAddr + "]";
			
			
			Server.log.println(conf, true);
		} catch(Exception e) {
			Server.log.println("Error while parsing configurations!", true);
			throw new Exception();
		}
	}

	/**
	 * @return the serverAddr
	 */
	public synchronized String getServerAddr() {
		return serverAddr;
	}

	/**
	 * Nr of rounds.
	 * @return the roundlimit
	 */
	public synchronized int getRoundLimit() {
		return roundLimit;
	}

	/**
	 * @return the port
	 */
	public synchronized int getPort() {
		return port;
	}

	/**
	 * Nr of cards dealed during rounds.
	 * @return the cardsDealedRound
	 */
	public synchronized int getCardsDealedRound() {
		return cardsDealedRound;
	}

	/**
	 * Nr of cards to put on table at first.
	 * @return the firstCardsTable
	 */
	public synchronized int getFirstCardsTable() {
		return firstCardsTable;
	}

	/**
	 * Player's max handsize.
	 * @return the maxPlayerHand
	 */
	public synchronized int getMaxPlayerHand() {
		return maxPlayerHand;
	}

	/**
	 * Nr of min players to start a game.
	 * @return the minPlayers
	 */
	public synchronized int getMinPlayers() {
		return minPlayers;
	}

	/**
	 * Server log writing options. 
	 * @return True if console writing is enabled, false if not.
	 */
	public synchronized boolean isConsole() {
		return console;
	}

	/**
	 * Server name.
	 * @return the serverName
	 */
	public synchronized String getServerName() {
		return serverName;
	}

	/**
	 * Nr of max players in game.
	 * @return the maxPlayers
	 */
	public synchronized int getMaxPlayers() {
		return maxPlayers;
	}

	/**
	 * Player's initial money.
	 * @return the initialMoney
	 */
	public synchronized int getInitialMoney() {
		return initialMoney;
	}
	
	
}
